//
//  SHYMediator+SHYMediatorModuleActions.m
//  SHYMediator
//
//  Created by huangyang on 16/6/27.
//  Copyright © 2016年 mucang. All rights reserved.
//

#import "SHYMediator+SHYMediatorModuleActions.h"

NSString * const kSHYMediatorTargetA = @"A";

NSString * const kSHYMediatorActionNativFetchDetailViewController = @"navieFetchDetailViewController";
NSString * const kSHYMediatorActionNativePresentImage = @"nativePresentImage";
NSString * const kSHYMediatorActionNativeNoImage = @"nativeNoImage";
NSString * const kSHYMediatorActionShowAlert = @"showAlert";

@implementation SHYMediator (SHYMediatorModuleAActions)

-(UIViewController *)SHYMediator_viewControllerForDetail {
    
    UIViewController* viewController = [self performTarget:kSHYMediatorTargetA action:kSHYMediatorActionNativFetchDetailViewController params:@{@"key":@"value"}];
    
    if ([viewController isKindOfClass:[UIViewController class]]) {
        return viewController;
    }
    else {
        return [[UIViewController alloc] init];
    }
}

-(void)SHYMediator_presentImage:(UIImage *)image {
    if (image) {
        [self performTarget:kSHYMediatorTargetA action:kSHYMediatorActionNativePresentImage params:@{@"image":image}];
    }
    else {
        [self performTarget:kSHYMediatorTargetA action:kSHYMediatorActionNativeNoImage params:@{@"image":[UIImage imageNamed:@"noImage"]}];
    }
}

-(void)SHYMediator_showAlertWithMessage:(NSString *)message cancelAction:(void (^)(NSDictionary *))cancelAction confirmAction:(void (^)(NSDictionary *))confirmAction {
    NSMutableDictionary* paramsToSend = [[NSMutableDictionary alloc] init];
    if (message) {
        paramsToSend[@"message"] = message;
    }
    
    if (cancelAction) {
        paramsToSend[@"cancelAction"] = cancelAction;
    }
    
    if (confirmAction) {
        paramsToSend[@"confirmAction"] = confirmAction;
    }
    
    [self performTarget:kSHYMediatorTargetA action:kSHYMediatorActionShowAlert params:paramsToSend];
}

@end
